﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnalysisSystemLog.Define.Utility;

namespace AnalysisSystemLog.FunctionMenu
{
    public class Jump
    {
        //目前焦点所处位置
        private int JumpIndex = 0; 

        /** 
         * \brief 跳转到下一个jtd中表示的（开关机）处
         * 
         * \param jtd 跳转方向
         */
        public void JumpToNext(LogConstant.JumpToDirection jtd)
        {
            if (jtd == LogConstant.JumpToDirection.PowerDown)
            {
                JumpToString(1, new string[] { "非正常关机" });
            }
            else if (jtd == LogConstant.JumpToDirection.PowerOn)
            {
                JumpToString(1, new string[] { "非正常开机" });
            }
            else if (jtd == LogConstant.JumpToDirection.PowerUpAndDown)
            {
                JumpToString(1, new string[] { "非正常开机", "非正常关机" });
            }
        }

        /** 
         * \brief 跳转到上一个jtd中表示的（开关机）处
         * 
         * \param jtd 跳转方向
         */
        public void JumpToUp(LogConstant.JumpToDirection jtd)
        {
            if (jtd == LogConstant.JumpToDirection.PowerDown)
            {
                JumpToString(0, new string[] { "非正常关机" });
            }
            else if (jtd == LogConstant.JumpToDirection.PowerOn)
            {
                JumpToString(0, new string[] { "非正常开机" });
            }
            else if (jtd == LogConstant.JumpToDirection.PowerUpAndDown)
            {
                JumpToString(0, new string[] { "非正常关机", "非正常开机" });
            }
        }

        /**
          * \brief 根据JumpDirection来决定在JumpIndex的上还是下查找说明为str的项
          *
          * \param jumpDirection 跳转方向
          * \param str 消息内容
          */
        public void JumpToString(int jumpDirection, params string[] str)
        {
            //int iItemCount = listViewShow.Items.Count;

            //if (jumpDirection == 0)
            //{
            //    JumpIndex = JumpIndex - 1 < 0 ? iItemCount - 1 : JumpIndex - 1;
            //    int j = 0; //只允许goto一次
            //jls:
            //    int i;
            //    for (i = JumpIndex; i > 0; i--)
            //    {
            //        if (CompareToStringArray(i, str))
            //        {
            //            return;
            //        }
            //    }
            //    if (i == 0 && j != 0)
            //    {
            //        return;
            //    }
            //    j++;
            //    JumpIndex = iItemCount - 1;
            //    goto jls;
            //}
            //else if (jumpDirection == 1)
            //{
            //    JumpIndex = JumpIndex + 1 >= iItemCount ? 0 : JumpIndex + 1;
            //    int j = 0;
            //JLS:
            //    int i;
            //    for (i = JumpIndex; i < iItemCount; i++)
            //    {
            //        if (CompareToStringArray(i, str))
            //        {
            //            return;
            //        }
            //    }
            //    if (i == iItemCount && j != 0)
            //    {
            //        return;
            //    }
            //    j++;
            //    JumpIndex = 0;
            //    goto JLS;
            //}
        }
    }
}
